package com.huitone.smspfm.interfacz.model;

import java.util.List;

import com.huitone.smspfm.interfacz.logger.ExtLogger;

import com.bin.common.utils.StringUtils;

/**   
* @Title SmsReport.java 
* @Package com.huitone.smspfm.interfacz.model 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年7月6日 下午2:21:40 
* @version V1.0   
*/
public class SmsReport {
	
	private static final ExtLogger logger = ExtLogger.create(SmsReport.class);
	
	protected String srvNode = null;
	protected String serviceCode = null;
	protected String phoneNumber = null;
	protected String gateLinkId = null;
	protected String sendResult = null;
	protected String recvErrorCode = null;
	protected String dealResult = null;
	protected Integer reportFlag = null;
	protected String serailSegment = null;
	protected String sendPort = null;
	protected String orgSrvNode = null;
	protected String orgSerialNo = null;
	protected Integer notifyType = null;
	protected String notifyListEl = null;
	
	protected Long orgSerialPart1 = null;
	protected Long orgSerialPart2 = null;
	protected Long orgSerialPart3 = null;
	protected String orgSerial = null;
	
	public static SmsReport parse(List<String> list) {
		
		SmsReport report = new SmsReport();
		
		try {
			
			report.setNotifyListEl(StringUtils.toString(list.get(13)));
			
			report.setSrvNode(StringUtils.toString(list.get(0)));
			report.setServiceCode(StringUtils.toString(list.get(1)));
			report.setPhoneNumber(StringUtils.toString(list.get(2)));
			report.setGateLinkId(StringUtils.toString(list.get(3)));
			report.setSendResult(StringUtils.toString(list.get(4)));
			report.setRecvErrorCode(StringUtils.toString(list.get(5)));
			report.setDealResult(StringUtils.toString(list.get(6)));
			report.setReportFlag(StringUtils.strToInteger(list.get(7), 2));
			report.setSerailSegment(StringUtils.toString(list.get(8)));
			report.setSendPort(StringUtils.toString(list.get(9)));
			report.setOrgSrvNode(StringUtils.toString(list.get(10)));
			report.setOrgSerialNo(StringUtils.toString(list.get(11)));
			report.setNotifyType(StringUtils.strToInteger(list.get(12), -1));
			
		} catch (Exception e) {
			logger.error("状态报告解析异常", e);
		}
		
		return report;
	}
	
	public boolean isWellInformed() {
		return !StringUtils.isEmpty(srvNode) 
				&& !StringUtils.isEmpty(serviceCode)
				&& !StringUtils.isEmpty(phoneNumber)
				&& !StringUtils.isEmpty(serailSegment)
				&& notifyType != null
				&& reportFlag != null
				&& orgSerialPart1 != null
				&& orgSerialPart2 != null
				&& orgSerialPart3 != null;
	}
	
	public String getSrvNode() {
		return srvNode;
	}
	public void setSrvNode(String srvNode) {
		this.srvNode = srvNode;
	}
	public String getServiceCode() {
		return serviceCode;
	}
	public void setServiceCode(String serviceCode) {
		this.serviceCode = serviceCode;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public Integer getNotifyType() {
		return notifyType;
	}
	public void setNotifyType(Integer notifyType) {
		this.notifyType = notifyType;
	}
	public String getGateLinkId() {
		return gateLinkId;
	}
	public void setGateLinkId(String gateLinkId) {
		this.gateLinkId = gateLinkId;
	}
	public String getSendResult() {
		return sendResult;
	}
	public void setSendResult(String sendResult) {
		this.sendResult = sendResult;
	}
	public String getRecvErrorCode() {
		return recvErrorCode;
	}
	public void setRecvErrorCode(String recvErrorCode) {
		this.recvErrorCode = recvErrorCode;
	}
	public String getDealResult() {
		return dealResult;
	}
	public void setDealResult(String dealResult) {
		this.dealResult = dealResult;
	}
	public Integer getReportFlag() {
		return reportFlag;
	}
	public void setReportFlag(Integer reportFlag) {
		this.reportFlag = reportFlag;
	}
	public String getSerailSegment() {
		return serailSegment;
	}
	public void setSerailSegment(String serailSegment) {
		this.serailSegment = serailSegment;
		
		String[] strings = StringUtils.split(serailSegment, ",");
		
		if (strings != null) {
			try {
				setOrgSerialPart1(StringUtils.tolong(strings[0]));
				setOrgSerialPart2(StringUtils.tolong(strings[1]));
				setOrgSerialPart3(StringUtils.tolong(strings[2]));
			} catch (Exception e) {
				logger.error("解析状态报告的序列SerialSegment时出错:" + e.getClass().getName() + ":" + e.getMessage() + 
						", 其中SerialSegment字段信息为:" + serailSegment + ", 从通知队列读取的[序列:号码:类型]为:" + notifyListEl);
			}
		}
		setOrgSerial(StringUtils.replace(serailSegment, ",", ""));
	}
	public Long getOrgSerialPart1() {
		return orgSerialPart1;
	}
	public void setOrgSerialPart1(Long orgSerialPart1) {
		this.orgSerialPart1 = orgSerialPart1;
	}
	public Long getOrgSerialPart2() {
		return orgSerialPart2;
	}
	public void setOrgSerialPart2(Long orgSerialPart2) {
		this.orgSerialPart2 = orgSerialPart2;
	}
	public Long getOrgSerialPart3() {
		return orgSerialPart3;
	}
	public void setOrgSerialPart3(Long orgSerialPart3) {
		this.orgSerialPart3 = orgSerialPart3;
	}

	@Override
	public String toString() {
		return "SmsReport [srvNode=" + srvNode + ", serviceCode=" + serviceCode + ", phoneNumber=" + phoneNumber
		        + ", gateLinkId=" + gateLinkId + ", sendResult=" + sendResult + ", recvErrorCode=" + recvErrorCode
		        + ", dealResult=" + dealResult + ", reportFlag=" + reportFlag + ", serailSegment=" + serailSegment
		        + ", sendPort=" + sendPort + ", orgSrvNode=" + orgSrvNode + ", orgSerialNo=" + orgSerialNo
		        + ", notifyType=" + notifyType + ", notifyListEl=" + notifyListEl + ", orgSerialPart1=" + orgSerialPart1
		        + ", orgSerialPart2=" + orgSerialPart2 + ", orgSerialPart3=" + orgSerialPart3 + ", orgSerial="
		        + orgSerial + "]";
	}

	public String getOrgSerial() {
		return orgSerial;
	}

	public void setOrgSerial(String orgSerial) {
		this.orgSerial = orgSerial;
	}

	public String getSendPort() {
		return sendPort;
	}

	public void setSendPort(String sendPort) {
		this.sendPort = sendPort;
	}

	public String getOrgSrvNode() {
		return orgSrvNode;
	}

	public void setOrgSrvNode(String orgSrvNode) {
		this.orgSrvNode = orgSrvNode;
	}

	public String getOrgSerialNo() {
		return orgSerialNo;
	}

	public void setOrgSerialNo(String orgSerialNo) {
		this.orgSerialNo = orgSerialNo;
	}

	public String getNotifyListEl() {
		return notifyListEl;
	}

	public void setNotifyListEl(String notifyListEl) {
		this.notifyListEl = notifyListEl;
	}
}
